package com.wusuowei.shiro_jwt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wusuowei.shiro_jwt.mapper.ProductMapper;
import com.wusuowei.shiro_jwt.model.po.Product;
import com.wusuowei.shiro_jwt.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements ProductService {
    @Autowired
    private ProductMapper productMapper;

    @Override
    public Page<Product> findPage(Page<Product> page, String proname, String cname, String proprice) {


        // 获取总记录数
        int total = productMapper.countProducts(proname, cname, proprice);
        page.setTotal(total);

        // 获取分页数据
        Page<Product> page1 = productMapper.findPage(page, proname, cname, proprice);
        List<Product> records = page1.getRecords();
        page.setRecords(records);

        return page;
    }

    public Product getDeletedProductById(Integer id) {
        return productMapper.getDeletedProductById(id);
    }

}
